package com.bjc.platform.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonBackReference;

@Entity
@Table(name = "adm_role")
public class AdmRole extends BaseObject implements Serializable {
	private Long id;
	private String roleName;
	private String roleType;
	private String roleCode;
	private String discription;
	private String inbuilt;
	private Long sort;
	private String remark;
	private Long creator;
	private Date createTime;
	private Long updater;
	private Date updateTime;
	private boolean flag;

	private Set<AdmAuthority> authorities = new HashSet<AdmAuthority>();

	@Id
	@Column(columnDefinition="int")
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "role_name", length = 255)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Column(name = "role_type")
	public String getRoleType() {
		return this.roleType;
	}

	public void setRoleType(String roleType) {
		this.roleType = roleType;
	}

	@Column(name = "role_code", length = 255)
	public String getRoleCode() {
		return this.roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	@Column(name = "discription", length = 255)
	public String getDiscription() {
		return this.discription;
	}

	public void setDiscription(String discription) {
		this.discription = discription;
	}

	@Column(name = "inbuilt", length = 1)
	public String getInbuilt() {
		return this.inbuilt;
	}

	public void setInbuilt(String inbuilt) {
		this.inbuilt = inbuilt;
	}

	@Column(columnDefinition="int", name = "sort")
	public Long getSort() {
		return this.sort;
	}

	public void setSort(Long sort) {
		this.sort = sort;
	}

	@Column(name = "remark", length = 255)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(columnDefinition="int", name = "creator", nullable = false)
	public Long getCreator() {
		return this.creator;
	}

	public void setCreator(Long creator) {
		this.creator = creator;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(columnDefinition="int", name = "updater")
	public Long getUpdater() {
		return this.updater;
	}

	public void setUpdater(Long updater) {
		this.updater = updater;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time")
	public Date getUpdateTime() {
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "flag", nullable = false, length = 1)
	public boolean isFlag() {
		return this.flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	@JsonBackReference
	@OneToMany(cascade = CascadeType.REMOVE,mappedBy="admRole", fetch=FetchType.EAGER)
	public Set<AdmAuthority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<AdmAuthority> authorities) {
		this.authorities = authorities;
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		AdmRole pojo = (AdmRole) o;
		if (id != null) {
			if (id != pojo.id)
				return false;
		}
		if (roleName != null ? !roleName.equals(pojo.roleName)
				: pojo.roleName != null)
			return false;
		if (roleType != null ? !roleType.equals(pojo.roleType)
				: pojo.roleType != null)
			return false;
		if (roleCode != null ? !roleCode.equals(pojo.roleCode)
				: pojo.roleCode != null)
			return false;
		if (discription != null ? !discription.equals(pojo.discription)
				: pojo.discription != null)
			return false;
		if (inbuilt != null ? !inbuilt.equals(pojo.inbuilt)
				: pojo.inbuilt != null)
			return false;
		if (sort != null ? !sort.equals(pojo.sort) : pojo.sort != null)
			return false;
		if (remark != null ? !remark.equals(pojo.remark) : pojo.remark != null)
			return false;
		if (creator != null ? !creator.equals(pojo.creator)
				: pojo.creator != null)
			return false;
		if (createTime != null ? !createTime.equals(pojo.createTime)
				: pojo.createTime != null)
			return false;
		if (updater != null ? !updater.equals(pojo.updater)
				: pojo.updater != null)
			return false;
		if (updateTime != null ? !updateTime.equals(pojo.updateTime)
				: pojo.updateTime != null)
			return false;
		if (flag != pojo.flag) {
			return false;
		}

		return true;
	}

	public int hashCode() {
		int result = 0;
		result = (roleName != null ? roleName.hashCode() : 0);
		if (id != null) {
			result = 31 * result + (id != null ? id.hashCode() : 0);
		}
		result = 31 * result + (roleType != null ? roleType.hashCode() : 0);
		result = 31 * result + (roleCode != null ? roleCode.hashCode() : 0);
		result = 31 * result
				+ (discription != null ? discription.hashCode() : 0);
		result = 31 * result + (inbuilt != null ? inbuilt.hashCode() : 0);
		result = 31 * result + (sort != null ? sort.hashCode() : 0);
		result = 31 * result + (remark != null ? remark.hashCode() : 0);
		result = 31 * result + (creator != null ? creator.hashCode() : 0);
		result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
		result = 31 * result + (updater != null ? updater.hashCode() : 0);
		result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);

		return result;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer(getClass().getSimpleName());

		sb.append(" [");
		sb.append("id").append("='").append(getId()).append("', ");
		sb.append("roleName").append("='").append(getRoleName()).append("', ");
		sb.append("roleType").append("='").append(getRoleType()).append("', ");
		sb.append("roleCode").append("='").append(getRoleCode()).append("', ");
		sb.append("discription").append("='").append(getDiscription())
				.append("', ");
		sb.append("inbuilt").append("='").append(getInbuilt()).append("', ");
		sb.append("sort").append("='").append(getSort()).append("', ");
		sb.append("remark").append("='").append(getRemark()).append("', ");
		sb.append("creator").append("='").append(getCreator()).append("', ");
		sb.append("createTime").append("='").append(getCreateTime())
				.append("', ");
		sb.append("updater").append("='").append(getUpdater()).append("', ");
		sb.append("updateTime").append("='").append(getUpdateTime())
				.append("', ");
		sb.append("flag").append("='").append(isFlag()).append("'");
		sb.append("]");

		return sb.toString();
	}

}
